package com.itboye.textileexpres.order;

import java.sql.Clob;
import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.textileexpes.beans.MyOrderBeans;
import com.itboye.textileexpes.beans.OrderDeltilteBeans;
import com.itboye.textileexpes.presenter.MyOrderPresenter;
import com.itboye.textileexpres.R;
import com.itboye.textileexpres.base.BaseActivity;
import com.itboye.textileexpres.base.ResultEntity;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.util.XImageLoader;
import com.itboye.textileexptes.config.GlobalConfig;

public class ActvityOrderDetail extends BaseActivity implements
		OnClickListener, Observer {
	TextView title;
	ImageView back, img_other;
	String type;
	MyOrderPresenter orderPresenter;
	OrderDeltilteBeans beans;
	String order_code;
	private TextView goods_name1_tv;
	private TextView order_num;
	private TextView goods_name2_tv;
	private TextView goods_detail_tv;
	private TextView color_tv, price_tv, num_tv, create_time;
	String addre;
	private TextView tvshouhuo, textPhone, textPadd, faburen, cole, tvyunfei,
			tvprice;
	private ImageView goods_img;

	private TextView btnDelete;
	private TextView dengdaipingjia;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_order_detail;
	}

	@Override
	public void onMyCreate() {
		title.setText("订单详情");
		img_other.setVisibility(View.GONE);
		// TODO Auto-generated method stub
		orderPresenter = new MyOrderPresenter(this);
		beans = new OrderDeltilteBeans();
		order_code = getIntent().getStringExtra("order_code");
		orderPresenter.getorder(IsMobileNumPhone.isUid(), order_code);
		type = getIntent().getStringExtra("type");
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.back:
			finish();
			break;
		case R.id.btnDelete:
			orderPresenter.getDelete("39", order_code);
			break;
		default:
			break;
		}
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == orderPresenter.Xiang_success) {
				beans = (OrderDeltilteBeans) entity.getData();
				getCounte(beans);
			} else if (entity.getEventType() == orderPresenter.Delete_success) {
				toast(entity.getData()+"");
				
			}
		}
	}

	public void getCounte(OrderDeltilteBeans beans) {
		int length = beans.getItems().size();

		// tvshouhuo,textPhone,textPadd,faburen,cole,tvyunfei,tvprice
		addre = beans.get_address().getCountry()
				+ beans.get_address().getProvince()
				+ beans.get_address().getDetailinfo();
		tvshouhuo.setText(beans.getUpdatetime());
		textPhone.setText(beans.get_address().getMobile());
		textPadd.setText(addre);
		faburen.setText(beans.getPublisher_name());
		
		if(beans.getCs_status().equals("1")){
			dengdaipingjia.setText("买家已经发货");
		}
		order_num.setText(order_code);

		for (int i = 0; i < length; i++) {
			goods_name1_tv.setText(beans.getPublisher_name());
			goods_name2_tv.setText(beans.getItems().get(i).getName());
			goods_detail_tv.setText(beans.getPublisher_name());
			color_tv.setText(beans.getItems().get(i).getSku_desc());
			price_tv.setText(beans.getItems().get(i).getPrice());
			create_time.setText(beans.getCreatetime());
			num_tv.setText(beans.getItems().get(i).getCount());
			tvyunfei.setText(beans.getItems().get(i).getOri_price() + "元");
			tvprice.setText(beans.getItems().get(i).getDt_origin_country());
			XImageLoader.load(
					GlobalConfig.IMAGE_DOUBLE
							+ beans.getItems().get(i).getImg(), goods_img);

		}

	}

}
